﻿#include "servocontrol.h"
#include "ui_servocontrol.h"
#include "global.h"
#include <QMessageBox>
ServoControl::ServoControl(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ServoControl)
{
    ui->setupUi(this);
    //主窗口关闭，一同关闭子窗口
    setAttribute(Qt::WA_QuitOnClose,false);

    workModeList =QStringList({"脉冲模式","立即速度模式","力矩模式","位置模式","速度模式","找原点模式","插补模式"});
    workModeList_Step =QStringList({"脉冲模式","位置模式","速度模式","找原点模式"});
    ui->cb_rwwokemode->blockSignals(true);
    ui->cb_rwwokemode->addItems(workModeList);
    ui->cb_rwwokemode->blockSignals(false);

    ui->cb_rwwokemode_2->blockSignals(true);
    ui->cb_rwwokemode_2->addItems(workModeList);
    ui->cb_rwwokemode_2->blockSignals(false);

    ui->cb_rwwokemode_3->blockSignals(true);
    ui->cb_rwwokemode_3->addItems(workModeList);
    ui->cb_rwwokemode_3->blockSignals(false);

    ui->cb_rwwokemode_4->blockSignals(true);
    ui->cb_rwwokemode_4->addItems(workModeList_Step);
    ui->cb_rwwokemode_4->blockSignals(false);

    workModeMap[-4] = 0;
    workModeMap[-3] = 1;
    workModeMap[4] = 2;
    workModeMap[1] = 3;
    workModeMap[3] = 4;
    workModeMap[6] = 5;
    workModeMap[7] = 6;

    workModeMap_Step[-4] = 0;
    workModeMap_Step[1] =1;
    workModeMap_Step[3] = 2;
    workModeMap_Step[6] = 3;

    ui->cb_rwcanrate->blockSignals(true);
    ui->cb_rwcanrate->addItems({"1000","500","250","125","50"});
    ui->cb_rwcanrate->blockSignals(false);

    ui->cb_rwcanrate_2->blockSignals(true);
    ui->cb_rwcanrate_2->addItems({"1000","500","250","125","50"});
    ui->cb_rwcanrate_2->blockSignals(false);

    ui->cb_rwcanrate_3->blockSignals(true);
    ui->cb_rwcanrate_3->addItems({"1000","500","250","125","50"});
    ui->cb_rwcanrate_3->blockSignals(false);

    ui->cb_rwcanrate_4->blockSignals(true);
    ui->cb_rwcanrate_4->addItems({"1000","500","250","125","50"});
    ui->cb_rwcanrate_4->blockSignals(false);
//    QTimer* t = new QTimer(this);//加入对象树
//    t->start(1000);
//    //以lambda表达式的形式设置槽函数
//    connect(t, &QTimer::timeout, [=]{
//        if(ui->ip_roworkmode->hasFocus() == false)
//            ui->ip_roworkmode->setText("111");
//    });

}

ServoControl::~ServoControl()
{
    qDebug()<<"xigou";
    delete ui;
}

void ServoControl::showEvent(QShowEvent *e)
{
    if(this->focusWidget()){
        qDebug() << this->focusWidget()->objectName();
        this->focusWidget()->clearFocus();
    }
    QWidget::showEvent(e);
}

bool ServoControl::stringToint(QString str, int &value,int base)
{
    bool ok ;
    value = str.toInt( &ok,base);
    return ok;
}

void ServoControl::delay_msec(unsigned int msec)
{
    //定义一个新的事件循环
    QEventLoop loop;
    //创建单次定时器,槽函数为事件循环的退出函数
    QTimer::singleShot(msec, &loop, SLOT(quit()));
    //事件循环开始执行,程序会卡在这里,直到定时时间到,本循环被退出
    loop.exec();
}

InOutCabCommand_Board ServoControl::packInOutCabCmd()
{
    InOutCabCommand_Board cmd;
    cmd.PortLocation_X = ui->ip_portx->text().toInt();
    cmd.PortLocation_Y = ui->ip_porty->text().toInt();
    cmd.StorgeLocation_X = ui->ip_storgex->text().toInt();
    cmd.StorgeLocation_Y = ui->ip_storgey->text().toInt();
    if(ui->ck_storge->checkState() == Qt::CheckState::Checked)
        cmd.Type = ARVCMDTYPE::type_incab;
    else
        cmd.Type = ARVCMDTYPE::type_outcab;
    if(ui->ck_havecmdnext->checkState() == Qt::CheckState::Checked)
        cmd.HaveNext = true;
    else
        cmd.HaveNext = false;
    if(ui->ck_facea->checkState() == Qt::CheckState::Checked)
    {
        cmd.Face = ARVCMDFACE::face_a;
    }
    else
        cmd.Face = ARVCMDFACE::face_b;
    if(ui->ck_cmdstep->checkState() == Qt::CheckState::Checked)
    {
        cmd.isDebug = true;
        cmd.StepCnt = 1;
    }
    else
    {
        cmd.isDebug = false;
    }
    return cmd;
}

void ServoControl::slot_imgCmdResult(QImage img)
{
    QPixmap pixmap = QPixmap::fromImage(img.scaled(ui->lb_image->size()-QSize(5,5),Qt::KeepAspectRatio));
    ui->lb_image->setPixmap(pixmap);
    ui->lb_time->setText(QDateTime::currentDateTime().toString());
}

void ServoControl::slot_setParamsResult(QJsonObject Recdata)
{
    uint32_t objectIndex = Recdata.value("ObjectIndex").toInt();
    uint8_t deviceNo = Recdata.value("DeviceNo").toInt();
    if(Recdata.value("Status") == true)
    {
        if(deviceNo == servoCanNo[0])
        {
            switch (objectIndex) {
                case KincoServoManager::RW_WorkMode_int8://工作模式
                {
                    int workMode = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->cb_rwwokemode->blockSignals(true);
                    ui->cb_rwwokemode->setCurrentIndex(workModeMap[workMode]);
                    ui->cb_rwwokemode->blockSignals(false);
                    break;
                }
                case KincoServoManager::RW_ControlWord_u16://控制字
                {
                    uint16_t controlWord = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwcontrolword->setText(QString::number(controlWord,16));
                    break;
                }
                case KincoServoManager::RW_TargetPosition_int32://目标位置
                {
                    int positon = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetpositon->setText(QString::number(positon));
                    break;
                }
                case KincoServoManager::RW_TrapeSpeed_u32://梯形速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapespeed->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TrapeAcc_u32://梯形加速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapeacc->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TrapeDec_u32://梯形减速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapedcc->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TargetSpeed_int32://目标速度
                {
                    int data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetspeed->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TargetTorque_int16://目标扭矩
                {
                    int16_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetniuju->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_EncoderReset_u8://编码器数据复位
                {
                    uint8_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwencoder->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_CanRate_u8://can波特率
                {
                    int data = Recdata.value("Value").toInt();
                    if(data == 12)
                        data = 125;
                    else
                        data = data*10;
                    // 执行指令并获取执行结果
                    ui->cb_rwcanrate->blockSignals(true);
                    ui->cb_rwcanrate->setCurrentText(QString::number(data));
                     ui->cb_rwcanrate->blockSignals(false);
                    break;
                }
                case KincoServoManager::RW_CanHeartTime_u16://can心跳报文产生时间
                {
                    uint16_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwcanheart->setText(QString::number(data));
                    break;
                }
                default:
                    break;
            }
        }
        else if(deviceNo == servoCanNo[1])
        {
            switch (objectIndex) {
                case KincoServoManager::RW_WorkMode_int8://工作模式
                {
                    int workMode = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->cb_rwwokemode_2->blockSignals(true);
                    ui->cb_rwwokemode_2->setCurrentIndex(workModeMap[workMode]);
                    ui->cb_rwwokemode_2->blockSignals(false);
                    break;
                }
                case KincoServoManager::RW_ControlWord_u16://控制字
                {
                    uint16_t controlWord = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwcontrolword_2->setText(QString::number(controlWord,16));
                    break;
                }
                case KincoServoManager::RW_TargetPosition_int32://目标位置
                {
                    int positon = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetpositon_2->setText(QString::number(positon));
                    break;
                }
                case KincoServoManager::RW_TrapeSpeed_u32://梯形速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapespeed_2->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TrapeAcc_u32://梯形加速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapeacc_2->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TrapeDec_u32://梯形减速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapedcc_2->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TargetSpeed_int32://目标速度
                {
                    int data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetspeed_2->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TargetTorque_int16://目标扭矩
                {
                    int16_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetniuju_2->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_EncoderReset_u8://编码器数据复位
                {
                    uint8_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwencoder_2->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_CanRate_u8://can波特率
                {
                    int data = Recdata.value("Value").toInt();
                    if(data == 12)
                        data = 125;
                    else
                        data = data*10;
                    // 执行指令并获取执行结果
                    ui->cb_rwcanrate_2->blockSignals(true);
                    ui->cb_rwcanrate_2->setCurrentText(QString::number(data));
                     ui->cb_rwcanrate_2->blockSignals(false);
                    break;
                }
                case KincoServoManager::RW_CanHeartTime_u16://can心跳报文产生时间
                {
                    uint16_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwcanheart_2->setText(QString::number(data));
                    break;
                }
                default:
                    break;
            }
        }
        else if(deviceNo == servoCanNo[2])
        {
            switch (objectIndex) {
                case KincoServoManager::RW_WorkMode_int8://工作模式
                {
                    int workMode = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->cb_rwwokemode_3->blockSignals(true);
                    ui->cb_rwwokemode_3->setCurrentIndex(workModeMap[workMode]);
                    ui->cb_rwwokemode_3->blockSignals(false);
                    break;
                }
                case KincoServoManager::RW_ControlWord_u16://控制字
                {
                    uint16_t controlWord = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwcontrolword_3->setText(QString::number(controlWord,16));
                    break;
                }
                case KincoServoManager::RW_TargetPosition_int32://目标位置
                {
                    int positon = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetpositon_3->setText(QString::number(positon));
                    break;
                }
                case KincoServoManager::RW_TrapeSpeed_u32://梯形速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapespeed_3->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TrapeAcc_u32://梯形加速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapeacc_3->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TrapeDec_u32://梯形减速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapedcc_3->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TargetSpeed_int32://目标速度
                {
                    int data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetspeed_3->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TargetTorque_int16://目标扭矩
                {
                    int16_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetniuju_3->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_EncoderReset_u8://编码器数据复位
                {
                    uint8_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwencoder_3->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_CanRate_u8://can波特率
                {
                    int data = Recdata.value("Value").toInt();
                    if(data == 12)
                        data = 125;
                    else
                        data = data*10;
                    // 执行指令并获取执行结果
                    ui->cb_rwcanrate_3->blockSignals(true);
                    ui->cb_rwcanrate_3->setCurrentText(QString::number(data));
                     ui->cb_rwcanrate_3->blockSignals(false);
                    break;
                }
                case KincoServoManager::RW_CanHeartTime_u16://can心跳报文产生时间
                {
                    uint16_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwcanheart_3->setText(QString::number(data));
                    break;
                }
                default:
                    break;
            }
        }
        else if(deviceNo == servoCanNo[3])
        {
            switch (objectIndex) {
                case KincoServoManager::RW_WorkMode_int8://工作模式
                {
                    int workMode = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->cb_rwwokemode_4->blockSignals(true);
                    ui->cb_rwwokemode_4->setCurrentIndex(workModeMap_Step[workMode]);
                    ui->cb_rwwokemode_4->blockSignals(false);
                    break;
                }
                case KincoServoManager::RW_ControlWord_u16://控制字
                {
                    uint16_t controlWord = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwcontrolword_4->setText(QString::number(controlWord,16));
                    break;
                }
                case KincoServoManager::RW_TargetPosition_int32://目标位置
                {
                    int positon = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetpositon_4->setText(QString::number(positon));
                    break;
                }
                case KincoServoManager::RW_TrapeSpeed_u32://梯形速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapespeed_4->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TrapeAcc_u32://梯形加速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapeacc_4->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TrapeDec_u32://梯形减速度
                {
                    uint data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtrapedcc_4->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_TargetSpeed_int32://目标速度
                {
                    int data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwtargetspeed_4->setText(QString::number(data));
                    break;
                }
                case KincoServoManager::RW_CanRate_u8://can波特率
                {
                    int data = Recdata.value("Value").toInt();
                    if(data == 12)
                        data = 125;
                    else
                        data = data*10;
                    // 执行指令并获取执行结果
                    ui->cb_rwcanrate_4->blockSignals(true);
                    ui->cb_rwcanrate_4->setCurrentText(QString::number(data));
                     ui->cb_rwcanrate_4->blockSignals(false);
                    break;
                }
                case KincoServoManager::RW_CanHeartTime_u16://can心跳报文产生时间
                {
                    uint16_t data = Recdata.value("Value").toInt();
                    // 执行指令并获取执行结果
                    ui->ip_rwcanheart_4->setText(QString::number(data));
                    break;
                }
                default:
                    break;
            }
        }
    }
    else
    {
        QString log;
        if(Recdata.value("ErrorCode") == 0x00)
        {
            log = QString("电机站号%1,寄存器%2读写失败,失败原因：读写超时").arg(deviceNo).arg(Recdata.value("ObjectIndex").toInt());
        }
        else if(Recdata.value("ErrorCode") == 0x01)
        {
            log = QString("电机站号%1,寄存器%2读写失败,失败原因：发送失败").arg(deviceNo).arg(Recdata.value("ObjectIndex").toInt());
        }
        else if(Recdata.value("ErrorCode") == 0x02)
        {
            log = QString("电机站号%1,寄存器%2读写失败,失败原因：数据解析错误").arg(deviceNo).arg(Recdata.value("ObjectIndex").toInt());
        }
        else if(Recdata.value("ErrorCode") == 0x80)
        {
            uint32_t msg = Recdata.value("Msg").toInt();
            QString error;
            switch (msg) {
            case 0x05040001:
                error = "无效命令，未知或非法的Clien/Server命令字";
                break;
            case 0x06010001:
                error = "试图读只写对象参数";
                break;
            case 0x06010002:
                error = "试图写只读对象参数";
                break;
            case 0x06020000:
                error = "无效索引";
                break;
            case 0x06040041:
                error = "无法映射";
                break;
            case 0x06060000:
                error = "驱动器处于故障状态导致对象访问失败";
                break;
            case 0x06070010:
                error = "服务参数长度不匹配";
                break;
            case 0x06070012:
                error = "服务参数长度太大";
                break;
            case 0x06070013:
                error = "服务参数长度太小";
                break;
            case 0x06090011:
                error = "无效子索引";
                break;
            case 0x06090030:
                error = "超出对象参数设定范围";
                break;
            case 0x06090031:
                error = "写入数据数值太大";
                break;
            case 0x06090032:
                error = "写入数据数值太小";
                break;
            case 0x08000022:
                error = "由于当前设备状态导致数据不能传送或保存";
                break;
            }
            log = QString("电机站号%1,寄存器%2读写失败,失败原因：%2").arg(deviceNo).arg(Recdata.value("ObjectIndex").toInt()).arg(error);
        }
        emit sig_addLog("red",log);
        //mylog<<"ErrorCode:"<<Recdata.value("ErrorCode")<<" Msg:"<<Recdata.value("Msg");
    }
}

void ServoControl::slot_ParamsResult(QJsonObject data)
{//mylog<<data;
    uint8_t deviceno = data.value("DeviceNo").toInt();
    int8_t workmode = data.value("RoWorkMode").toInt();
    if(deviceno == servoCanNo[0])
    {
        if(workmode == 0)
            ui->ip_rowokemode->setText("0");
        else
            ui->ip_rowokemode->setText(workModeList.at(workModeMap[workmode]));

        uint16_t stateword = data.value("RoStateWord").toInt();
        ui->ip_rostateword->setText(QString::number(stateword,16));

        ui->ip_rorealposition->setText(QString::number(data.value("RoRealPosition").toInt()));

        ui->ip_rorealspeed->setText(QString::number(data.value("RoRealSpeed").toInt()));

        uint16_t realcurrent = data.value("RoRealCurrent").toInt();
        ui->ip_rorealcurrent->setText(QString::number(realcurrent));

        uint16_t warnword = data.value("RoWarnStateWord").toInt();
        ui->ip_rowarnword->setText(QString::number(warnword,16));

        uint8_t zaixian = data.value("RoHeart").toInt();
        if(zaixian>0)
            ui->lt_zx1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_zx1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerReady) != 0)
            ui->lt_zbsd1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_zbsd1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerOn) != 0)
            ui->lt_ysd1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_ysd1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Enable) != 0)
            ui->lt_sn1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_sn1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Fault) != 0)
            ui->lt_gz1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_gz1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_FbdOutVoltage) != 0)
            ui->lt_jzdysc1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_jzdysc1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_QuickStop) != 0)
            ui->lt_kstz1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_kstz1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerForbid) != 0)
            ui->lt_sdjz1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_sdjz1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Warning) != 0)
            ui->lt_jg1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_jg1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_TargetPositionArrive) != 0)
            ui->lt_mbwzd1->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_mbwzd1->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_InterLimitEnable) != 0)
            ui->lt_limit_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_limit_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        ui->cb_rwwokemode->blockSignals(true);
        ui->cb_rwwokemode->setCurrentIndex(workModeMap[data.value("RwWorkMode").toInt()]);
        ui->cb_rwwokemode->blockSignals(false);

        uint16_t controlword = data.value("RwControlWord").toInt();
        ui->ip_rwcontrolword->setText(QString::number(controlword,16));

        int32_t targetposition = data.value("RwTargetPosition").toInt();
        ui->ip_rwtargetpositon->setText(QString::number(targetposition));

        uint32_t trapespeed = data.value("RwTrapeSpeed").toInt();
        ui->ip_rwtrapespeed->setText(QString::number(trapespeed));

        uint32_t trapeacc = data.value("RwTrapeAcc").toInt();
        ui->ip_rwtrapeacc->setText(QString::number(trapeacc));

        uint32_t trapedec = data.value("RwTrapeDec").toInt();
        ui->ip_rwtrapedcc->setText(QString::number(trapedec));

        int32_t targetspeed =  data.value("RwTargetSpeed").toInt();
        ui->ip_rwtargetspeed->setText(QString::number(targetspeed));

        int16_t targettorque = data.value("RwTargetTorque").toInt();
        ui->ip_rwtargetniuju->setText(QString::number(targettorque));

        uint8_t encoderreset = data.value("RwEncoderReset").toInt();
        ui->ip_rwencoder->setText(QString::number(encoderreset));

        int32_t positivelimit = data.value("RwPositiveLimit").toInt();
        ui->ip_ropositivelimit->setText(QString::number(positivelimit));

        int32_t nagetivelimit = data.value("RwNagetiveLimit").toInt();
        ui->ip_ronagetivelimit->setText(QString::number(nagetivelimit));

        int8_t originmode = data.value("RwOriginMode").toInt();
        ui->ip_rworinginmode->setText(QString::number(originmode));

        int32_t canrate = data.value("RwCanRate").toInt();
        if(canrate == 12)
            canrate = 125;
        else
            canrate = canrate*10;
        ui->cb_rwcanrate->blockSignals(true);
        ui->cb_rwcanrate->setCurrentText(QString::number(canrate));
        ui->cb_rwcanrate->blockSignals(false);

        uint16_t hearttime = data.value("RwCanHeartTime").toInt();
        ui->ip_rwcanheart->setText(QString::number(hearttime));
    }
    else if(deviceno == servoCanNo[1])
    {
        if(workmode == 0)
            ui->ip_rowokemode_2->setText("0");
        else
            ui->ip_rowokemode_2->setText(workModeList.at(workModeMap[workmode]));

        uint16_t stateword = data.value("RoStateWord").toInt();
        ui->ip_rostateword_2->setText(QString::number(stateword,16));

        ui->ip_rorealposition_2->setText(QString::number(data.value("RoRealPosition").toInt()));

        ui->ip_rorealspeed_2->setText(QString::number(data.value("RoRealSpeed").toInt()));

        uint16_t realcurrent = data.value("RoRealCurrent").toInt();
        ui->ip_rorealcurrent_2->setText(QString::number(realcurrent));

        uint16_t warnword = data.value("RoWarnStateWord").toInt();
        ui->ip_rowarnword_2->setText(QString::number(warnword,16));

        uint8_t zaixian = data.value("RoHeart").toInt();
        if(zaixian>0)
            ui->lt_zx1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_zx1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerReady) != 0)
            ui->lt_zbsd1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_zbsd1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerOn) != 0)
            ui->lt_ysd1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_ysd1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Enable) != 0)
            ui->lt_sn1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_sn1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Fault) != 0)
            ui->lt_gz1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_gz1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_FbdOutVoltage) != 0)
            ui->lt_jzdysc1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_jzdysc1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_QuickStop) != 0)
            ui->lt_kstz1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_kstz1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerForbid) != 0)
            ui->lt_sdjz1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_sdjz1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Warning) != 0)
            ui->lt_jg1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_jg1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_TargetPositionArrive) != 0)
            ui->lt_mbwzd1_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_mbwzd1_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_InterLimitEnable) != 0)
            ui->lt_limit_2->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_limit_2->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        ui->cb_rwwokemode_2->blockSignals(true);
        ui->cb_rwwokemode_2->setCurrentIndex(workModeMap[data.value("RwWorkMode").toInt()]);
        ui->cb_rwwokemode_2->blockSignals(false);

        uint16_t controlword = data.value("RwControlWord").toInt();
        ui->ip_rwcontrolword_2->setText(QString::number(controlword,16));

        int32_t targetposition = data.value("RwTargetPosition").toInt();
        ui->ip_rwtargetpositon_2->setText(QString::number(targetposition));

        uint32_t trapespeed = data.value("RwTrapeSpeed").toInt();
        ui->ip_rwtrapespeed_2->setText(QString::number(trapespeed));

        uint32_t trapeacc = data.value("RwTrapeAcc").toInt();
        ui->ip_rwtrapeacc_2->setText(QString::number(trapeacc));

        uint32_t trapedec = data.value("RwTrapeDec").toInt();
        ui->ip_rwtrapedcc_2->setText(QString::number(trapedec));

        int32_t targetspeed =  data.value("RwTargetSpeed").toInt();
        ui->ip_rwtargetspeed_2->setText(QString::number(targetspeed));

        int16_t targettorque = data.value("RwTargetTorque").toInt();
        ui->ip_rwtargetniuju_2->setText(QString::number(targettorque));

        uint8_t encoderreset = data.value("RwEncoderReset").toInt();
        ui->ip_rwencoder_2->setText(QString::number(encoderreset));

        int32_t positivelimit = data.value("RwPositiveLimit").toInt();
        ui->ip_ropositivelimit_2->setText(QString::number(positivelimit));

        int32_t nagetivelimit = data.value("RwNagetiveLimit").toInt();
        ui->ip_ronagetivelimit_2->setText(QString::number(nagetivelimit));

        uint8_t servobreak = data.value("RwServoBreak").toInt();
        ui->ip_break->setText(QString::number(servobreak));

        int8_t originmode = data.value("RwOriginMode").toInt();
        ui->ip_rworinginmode_2->setText(QString::number(originmode));

        int32_t canrate = data.value("RwCanRate").toInt();
        if(canrate == 12)
            canrate = 125;
        else
            canrate = canrate*10;
        ui->cb_rwcanrate_2->blockSignals(true);
        ui->cb_rwcanrate_2->setCurrentText(QString::number(canrate));
        ui->cb_rwcanrate_2->blockSignals(false);

        uint16_t hearttime = data.value("RwCanHeartTime").toInt();
        ui->ip_rwcanheart_2->setText(QString::number(hearttime));

    }
    else if(deviceno == servoCanNo[2])
    {
        if(workmode == 0)
            ui->ip_rowokemode_3->setText("0");
        else
            ui->ip_rowokemode_3->setText(workModeList.at(workModeMap[workmode]));

        uint16_t stateword = data.value("RoStateWord").toInt();
        ui->ip_rostateword_3->setText(QString::number(stateword,16));

        ui->ip_rorealposition_3->setText(QString::number(data.value("RoRealPosition").toInt()));

        ui->ip_rorealspeed_3->setText(QString::number(data.value("RoRealSpeed").toInt()));

        uint16_t realcurrent = data.value("RoRealCurrent").toInt();
        ui->ip_rorealcurrent_3->setText(QString::number(realcurrent));

        uint16_t warnword = data.value("RoWarnStateWord").toInt();
        ui->ip_rowarnword_3->setText(QString::number(warnword,16));

        uint8_t zaixian = data.value("RoHeart").toInt();
        if(zaixian>0)
            ui->lt_zx_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_zx_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerReady) != 0)
            ui->lt_zbsd_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_zbsd_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerOn) != 0)
            ui->lt_ysd_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_ysd_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Enable) != 0)
            ui->lt_sn_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_sn_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Fault) != 0)
            ui->lt_gz_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_gz_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_FbdOutVoltage) != 0)
            ui->lt_jzdysc_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_jzdysc_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_QuickStop) != 0)
            ui->lt_kstz_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_kstz_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerForbid) != 0)
            ui->lt_sdjz_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_sdjz_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Warning) != 0)
            ui->lt_jg_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_jg_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_TargetPositionArrive) != 0)
            ui->lt_mbwzd_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_mbwzd_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_InterLimitEnable) != 0)
            ui->lt_limit_3->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_limit_3->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");


        ui->cb_rwwokemode_3->blockSignals(true);
        ui->cb_rwwokemode_3->setCurrentIndex(workModeMap[data.value("WorkMode").toInt()]);
        ui->cb_rwwokemode_3->blockSignals(false);

        uint16_t controlword = data.value("RwControlWord").toInt();
        ui->ip_rwcontrolword_3->setText(QString::number(controlword,16));

        int32_t targetposition = data.value("RwTargetPosition").toInt();
        ui->ip_rwtargetpositon_3->setText(QString::number(targetposition));

        uint32_t trapespeed = data.value("RwTrapeSpeed").toInt();
        ui->ip_rwtrapespeed_3->setText(QString::number(trapespeed));

        uint32_t trapeacc = data.value("RwTrapeAcc").toInt();
        ui->ip_rwtrapeacc_3->setText(QString::number(trapeacc));

        uint32_t trapedec = data.value("RwTrapeDec").toInt();
        ui->ip_rwtrapedcc_3->setText(QString::number(trapedec));

        int32_t targetspeed =  data.value("RwTargetSpeed").toInt();
        ui->ip_rwtargetspeed_3->setText(QString::number(targetspeed));

        int16_t targettorque = data.value("RwTargetTorque").toInt();
        ui->ip_rwtargetniuju_3->setText(QString::number(targettorque));

        uint8_t encoderreset = data.value("RwEncoderReset").toInt();
        ui->ip_rwencoder_3->setText(QString::number(encoderreset));

        int32_t positivelimit = data.value("RwPositiveLimit").toInt();
        ui->ip_ropositivelimit_3->setText(QString::number(positivelimit));

        int32_t nagetivelimit = data.value("RwNagetiveLimit").toInt();
        ui->ip_ronagetivelimit_3->setText(QString::number(nagetivelimit));

        int8_t originmode = data.value("RwOriginMode").toInt();
        ui->ip_rworinginmode_3->setText(QString::number(originmode));

        int32_t canrate = data.value("RwCanRate").toInt();
        if(canrate == 12)
            canrate = 125;
        else
            canrate = canrate*10;
        ui->cb_rwcanrate_3->blockSignals(true);
        ui->cb_rwcanrate_3->setCurrentText(QString::number(canrate));
        ui->cb_rwcanrate_3->blockSignals(false);

        uint16_t hearttime = data.value("RwCanHeartTime").toInt();
        ui->ip_rwcanheart_3->setText(QString::number(hearttime));

    }
    else if(deviceno == servoCanNo[3])
    {
        if(workmode == 0)
            ui->ip_rowokemode_4->setText("0");
        else
            ui->ip_rowokemode_4->setText(workModeList_Step.at(workModeMap_Step[workmode]));

        uint16_t stateword = data.value("RoStateWord").toInt();
        ui->ip_rostateword_4->setText(QString::number(stateword,16));

        ui->ip_rorealposition_4->setText(QString::number(data.value("RoRealPosition").toInt()));

        ui->ip_rorealspeed_4->setText(QString::number(data.value("RoRealSpeed").toInt()));

        uint16_t realcurrent = data.value("RoRealCurrent").toInt();
        ui->ip_rorealcurrent_4->setText(QString::number(realcurrent));

        uint16_t realvol = data.value("RoRealVoltage").toInt();
        ui->ip_rorealvoltage_4->setText(QString::number(realvol));

        uint8_t zaixian = data.value("RoHeart").toInt();
        if(zaixian>0)
            ui->lt_zx_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_zx_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerReady) != 0)
            ui->lt_zbsd_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_zbsd_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerOn) != 0)
            ui->lt_ysd_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_ysd_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Enable) != 0)
            ui->lt_sn_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_sn_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Fault) != 0)
            ui->lt_gz_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_gz_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_FbdOutVoltage) != 0)
            ui->lt_jzdysc_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_jzdysc_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_QuickStop) != 0)
            ui->lt_kstz_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_kstz_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_PowerForbid) != 0)
            ui->lt_sdjz_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_sdjz_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_Warning) != 0)
            ui->lt_jg_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_jg_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_TargetPositionArrive) != 0)
            ui->lt_mbwzd_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_mbwzd_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        if((stateword & KincoServoManager::Status_InterLimitEnable) != 0)
            ui->lt_limit_4->setStyleSheet("QLabel{background-color:green;border-radius: 12px;border:1px solid black;}");
        else
            ui->lt_limit_4->setStyleSheet("QLabel{background-color:red;border-radius: 12px;border:1px solid black;}");

        ui->cb_rwwokemode_4->blockSignals(true);
        ui->cb_rwwokemode_4->setCurrentIndex(workModeMap_Step[data.value("RwWorkMode").toInt()]);
        ui->cb_rwwokemode_4->blockSignals(false);

        uint16_t controlword = data.value("RwControlWord").toInt();
        ui->ip_rwcontrolword_4->setText(QString::number(controlword,16));

        int32_t targetposition = data.value("RwTargetPosition").toInt();
        ui->ip_rwtargetpositon_4->setText(QString::number(targetposition));

        uint32_t trapespeed = data.value("RwTrapeSpeed").toInt();
        ui->ip_rwtrapespeed_4->setText(QString::number(trapespeed));

        uint32_t trapeacc = data.value("RwTrapeAcc").toInt();
        ui->ip_rwtrapeacc_4->setText(QString::number(trapeacc));

        uint32_t trapedec = data.value("RwTrapeDec").toInt();
        ui->ip_rwtrapedcc_4->setText(QString::number(trapedec));

        int32_t targetspeed =  data.value("RwTargetSpeed").toInt();
        ui->ip_rwtargetspeed_4->setText(QString::number(targetspeed));

        int32_t positivelimit = data.value("RwPositiveLimit").toInt();
        ui->ip_ropositivelimit_4->setText(QString::number(positivelimit));

        int32_t nagetivelimit = data.value("RwNagetiveLimit").toInt();
        ui->ip_ronagetivelimit_4->setText(QString::number(nagetivelimit));

        int8_t originmode = data.value("RwOriginMode").toInt();
        ui->ip_rworinginmode_4->setText(QString::number(originmode));

        int32_t canrate = data.value("RwCanRate").toInt();
        if(canrate == 12)
            canrate = 125;
        else
            canrate = canrate*10;
        ui->cb_rwcanrate_4->blockSignals(true);
        ui->cb_rwcanrate_4->setCurrentText(QString::number(canrate));
        ui->cb_rwcanrate_4->blockSignals(false);

        uint16_t hearttime = data.value("RwCanHeartTime").toInt();
        ui->ip_rwcanheart_4->setText(QString::number(hearttime));

    }
    //解析电机位置状态
    QStringList strList = data.value("Location").toString().split(",");
    for(int8_t i=0;i<5;i++)
    {
        int8_t location = strList.at(i).toInt();
        switch (location) {
        case ServoControl::Location_Origin:
            if(i == 0)
                ui->lb_Xlocation->setText("原点");
            else if(i == 1)
                ui->lb_Ylocation->setText("原点");
            else if(i == 2)
                ui->lb_Rlocation->setText("原点");
            else if(i == 3)
                ui->lb_Zlocation->setText("原点");
            break;
        case Location_Origining:
            if(i == 0)
                ui->lb_Xlocation->setText("原点移动中");
            else if(i == 1)
                ui->lb_Ylocation->setText("原点移动中");
            else if(i == 2)
                ui->lb_Rlocation->setText("原点移动中");
            else if(i == 3)
                ui->lb_Zlocation->setText("原点移动中");
            break;
        case Location_FaceA:
            if(i == 2)
                ui->lb_Rlocation->setText("A面");
            else if(i == 3)
                ui->lb_Zlocation->setText("A面");
            break;
        case Location_FaceAing:
            if(i == 2)
                ui->lb_Rlocation->setText("A面移动中");
            else if(i == 3)
                ui->lb_Zlocation->setText("A面移动中");
            break;
        case Location_FaceB:
            if(i == 2)
                ui->lb_Rlocation->setText("B面");
            else if(i == 3)
                ui->lb_Zlocation->setText("B面");
            break;
        case Location_FaceBing:
            if(i == 2)
                ui->lb_Rlocation->setText("B面移动中");
            else if(i == 3)
                ui->lb_Zlocation->setText("B面移动中");
            break;
        case Location_Moving:
            if(i == 0)
                ui->lb_Xlocation->setText("货位移动中");
            else if(i == 1)
                ui->lb_Ylocation->setText("货位移动中");
            else if(i == 2)
                ui->lb_Rlocation->setText("任意移动中");
            else if(i == 3)
                ui->lb_Zlocation->setText("任意移动中");
            break;
        case Location_NoneOrigin:
            if(i == 0)
                ui->lb_Xlocation->setText("货位");
            else if(i == 1)
                ui->lb_Ylocation->setText("货位");
            else if(i == 2)
                ui->lb_Rlocation->setText("任意");
            else if(i == 3)
                ui->lb_Zlocation->setText("任意");
            break;
        case Location_Porting:
            if(i == 0)
                ui->lb_Xlocation->setText("出口移动中");
            else if(i == 1)
                ui->lb_Ylocation->setText("出口移动中");
            break;
        case Location_Port:
            if(i == 0)
                ui->lb_Xlocation->setText("出口");
            else if(i == 1)
                ui->lb_Ylocation->setText("出口");
            break;
        case Location_Clamping:
            ui->lb_RMlocation->setText("抓取中");
            break;
        case Location_Clamped:
            ui->lb_RMlocation->setText("已抓取");
            break;
        case Location_Loosening:
            ui->lb_RMlocation->setText("松开中");
            break;
        case Location_Loosened:
            ui->lb_RMlocation->setText("已松开");
            break;
        }
    }
}

void ServoControl::on_ip_rwcontrolword_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwcontrolword->text(),value,16))
    {
        //mylog<<"set rw controlword:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,value);
    }
    ui->ip_rwcontrolword->clearFocus();
    emit sig_addLog("black",QString("向横向移动电机发送控制字："+ui->ip_rwcontrolword->text()));
}

void ServoControl::on_ip_rwtargetpositon_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetpositon->text(),value,10))
    {
        //mylog<<"set rw targetposition:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_TargetPosition_int32,value);
    }
    ui->ip_rwtargetpositon->clearFocus();
    emit sig_addLog("black",QString("向横向移动电机发送目标位置："+ui->ip_rwtargetpositon->text()));
}

void ServoControl::on_ip_rwtrapespeed_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapespeed->text(),value,10))
    {
        //mylog<<"set rw trapespeed:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_TrapeSpeed_u32,value);
    }
    ui->ip_rwtrapespeed->clearFocus();
    emit sig_addLog("black",QString("向横向移动电机发送梯形速度："+ui->ip_rwtrapespeed->text()));
}

void ServoControl::on_ip_rwtrapeacc_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapeacc->text(),value,10))
    {
        //mylog<<"set rw trapeacc:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_TrapeAcc_u32,value);
    }
    ui->ip_rwtrapeacc->clearFocus();
    emit sig_addLog("black",QString("向横向移动电机发送梯形加速度："+ui->ip_rwtrapeacc->text()));
}

void ServoControl::on_ip_rwtrapedcc_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapedcc->text(),value,10))
    {
        //mylog<<"set rw trapedcc:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_TrapeDec_u32,value);
    }
    ui->ip_rwtrapedcc->clearFocus();
    emit sig_addLog("black",QString("向横向移动电机发送梯形减速度："+ui->ip_rwtrapedcc->text()));
}

void ServoControl::on_ip_rwtargetspeed_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetspeed->text(),value,10))
    {
        //mylog<<"set rw targetspeed:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_TargetSpeed_int32,value);
    }
    ui->ip_rwtargetspeed->clearFocus();
    emit sig_addLog("black",QString("向横向移动电机发送目标速度："+ui->ip_rwtargetspeed->text()));
}

void ServoControl::on_ip_rwtargetniuju_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetniuju->text(),value,10))
    {
        //mylog<<"set rw targetniuju:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_TargetTorque_int16,value);
    }
    ui->ip_rwtargetniuju->clearFocus();
    emit sig_addLog("black",QString("向横向移动电机发送目标扭矩："+ui->ip_rwtargetniuju->text()));
}

void ServoControl::on_ip_rwcanheart_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwcanheart->text(),value,10))
    {
        //mylog<<"set rw canheart:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_CanHeartTime_u16,value);
    }
    ui->ip_rwcanheart->clearFocus();
    emit sig_addLog("black",QString("向横向移动电机发送Can心跳时间："+ui->ip_rwcanheart->text()));
}

void ServoControl::on_ip_rwencoder_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwencoder->text(),value,10))
    {
        //mylog<<"set rw encoderreset:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_EncoderReset_u8,value);
    }
    ui->ip_rwencoder->clearFocus();
    emit sig_addLog("black",QString("向横向移动电机发送编码器通讯复位："+ui->ip_rwencoder->text()));
}

void ServoControl::on_cb_rwcanrate_currentTextChanged(const QString &arg1)
{
    int value;
    if(stringToint(arg1,value,10))
    {
        mylog<<"set rw canrate:"<<value;
        value = value/10;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_CanRate_u8,value);
    }
    emit sig_addLog("black",QString("向横向移动电机发送更改Can波特率："+ui->cb_rwcanrate->currentText()));
}

void ServoControl::on_bt_poweroff1_clicked()
{
    //emit sig_setControl(1,DispatchCore::ControlCmd_ServoPowerOff);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_MotorPowerOff);
    emit sig_addLog("black","向横向移动电机发送断电指令");
}

void ServoControl::on_bt_poweion1_clicked()
{
    //emit sig_setControl(1,DispatchCore::ControlCmd_ServoPowerOn);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_MotorPowerOn);
    emit sig_addLog("black","向横向移动电机发送上电指令");
}

void ServoControl::on_bt_quickstop1_clicked()
{
    //emit sig_setControl(1,DispatchCore::ControlCmd_ServoQuickStop);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_ShutDown);
    emit sig_addLog("black","向横向移动电机发送快速停止指令");
}

void ServoControl::on_bt_absolute1_clicked()
{
    //emit sig_setControl(1,DispatchCore::ControlCmd_ServoAbsolute);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_AbsoluteLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_AbsoluteLocationStep2);
    emit sig_addLog("black","向横向移动电机发送绝对定位指令");
}

void ServoControl::on_bt_relative1_clicked()
{
    //emit sig_setControl(1,DispatchCore::ControlCmd_ServoRelative);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_RelativeLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_RelativeLocationStep2);
    emit sig_addLog("black","向横向移动电机发送相对定位指令");
}

void ServoControl::on_bt_follow1_clicked()
{
    //emit sig_setControl(1,DispatchCore::ControlCmd_ServoFollow);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_Follow);
    emit sig_addLog("black","向横向移动电机发送根据目标位置变化立即绝对定位指令");
}

void ServoControl::on_bt_oringin1_clicked()
{
    //emit sig_setControl(1,DispatchCore::ControlCmd_ServoOrigin);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_OringLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_OringLocationStep2);
    emit sig_addLog("black","向横向移动电机发送原点定位指令");
}

void ServoControl::on_bt_clearfault1_clicked()
{
    //emit sig_setControl(1,DispatchCore::ControlCmd_ServoClaerFault);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_ClearInterFault);
    emit sig_addLog("black","向横向移动电机发送清楚内部故障指令");
}

void ServoControl::on_cb_rwwokemode_currentIndexChanged(int index)
{
    int8_t workmode = workModeMap.key(index);
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_WorkMode_int8,workmode);
}

void ServoControl::on_bt_save1_clicked()
{
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_Save_uint8,KincoServoManager::Command_Save);
    emit sig_addLog("black","向横向移动电机发送保存指令");
}

void ServoControl::on_bt_reboot1_clicked()
{
    emit sig_setParams(servoCanNo[0],KincoServoManager::RW_DeviceReboot_uint16,KincoServoManager::Comman_Reboot);
    emit sig_addLog("black","向横向移动电机发送重启指令");
}

void ServoControl::on_cb_rwwokemode_2_currentIndexChanged(int index)
{
    int8_t workmode = workModeMap.key(index);
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_WorkMode_int8,workmode);
}

void ServoControl::on_ip_rwcontrolword_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwcontrolword_2->text(),value,16))
    {
        //mylog<<"set rw controlword:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,value);
    }
    ui->ip_rwcontrolword_2->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送控制字："+ui->ip_rwcontrolword_2->text()));
}

void ServoControl::on_ip_rwtargetpositon_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetpositon_2->text(),value,10))
    {
        //mylog<<"set rw targetposition:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_TargetPosition_int32,value);
    }
    ui->ip_rwtargetpositon_2->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送目标位置："+ui->ip_rwtargetpositon_2->text()));
}

void ServoControl::on_ip_rwtrapespeed_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapespeed_2->text(),value,10))
    {
        //mylog<<"set rw trapespeed:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_TrapeSpeed_u32,value);
    }
    ui->ip_rwtrapespeed_2->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送梯形速度："+ui->ip_rwtrapespeed_2->text()));
}

void ServoControl::on_ip_rwtrapeacc_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapeacc_2->text(),value,10))
    {
        //mylog<<"set rw trapespeed:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_TrapeAcc_u32,value);
    }
    ui->ip_rwtrapeacc_2->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送梯形加速度："+ui->ip_rwtrapeacc_2->text()));
}

void ServoControl::on_ip_rwtrapedcc_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapedcc_2->text(),value,10))
    {
        //mylog<<"set rw trapedcc:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_TrapeDec_u32,value);
    }
    ui->ip_rwtrapedcc_2->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送梯形减速度："+ui->ip_rwtrapedcc_2->text()));
}

void ServoControl::on_ip_rwtargetspeed_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetspeed_2->text(),value,10))
    {
        //mylog<<"set rw targetspeed:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_TargetSpeed_int32,value);
    }
    ui->ip_rwtargetspeed_2->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送目标速度："+ui->ip_rwtargetspeed_2->text()));
}

void ServoControl::on_ip_rwtargetniuju_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetniuju_2->text(),value,10))
    {
        //mylog<<"set rw targetniuju:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_TargetTorque_int16,value);
    }
    ui->ip_rwtargetniuju_2->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送目标扭矩："+ui->ip_rwtargetniuju_2->text()));
}

void ServoControl::on_cb_rwcanrate_2_currentTextChanged(const QString &arg1)
{
    int value;
    if(stringToint(arg1,value,10))
    {
        //mylog<<"set rw canrate:"<<value;
        value = value/10;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_CanRate_u8,value);
    }
    emit sig_addLog("black",QString("向纵向移动电机发送更改Can波特率："+ui->cb_rwcanrate_2->currentText()));
}

void ServoControl::on_ip_rwcanheart_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwcanheart_2->text(),value,10))
    {
        //mylog<<"set rw canheart:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_CanHeartTime_u16,value);
    }
    ui->ip_rwcanheart_2->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送Can心跳时间："+ui->ip_rwcanheart_2->text()));
}

void ServoControl::on_ip_rwencoder_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwencoder_2->text(),value,10))
    {
        //mylog<<"set rw encoderreset:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_EncoderReset_u8,value);
    }
    ui->ip_rwencoder_2->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送编码器通讯复位："+ui->ip_rwencoder_2->text()));
}

void ServoControl::on_ip_break_returnPressed()
{
    int value;
    if(stringToint(ui->ip_break->text(),value,10))
    {
        //mylog<<"set rw encoderreset:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ServoBreak_u8,value);
    }
    ui->ip_break->clearFocus();
    emit sig_addLog("black",QString("向纵向移动电机发送设置电机抱闸："+ui->ip_break->text()));
}

void ServoControl::on_bt_poweroff_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_MotorPowerOff);
    emit sig_addLog("black","向纵向移动电机发送断电指令");
}

void ServoControl::on_bt_poweion_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_MotorPowerOn);
    emit sig_addLog("black","向纵向移动电机发送上电指令");
}

void ServoControl::on_bt_quickstop_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_ShutDown);
    emit sig_addLog("black","向纵向移动电机发送快速停止指令");
}

void ServoControl::on_bt_absolute_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_AbsoluteLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_AbsoluteLocationStep2);
    emit sig_addLog("black","向纵向移动电机发送绝对定位指令");
}

void ServoControl::on_bt_relative_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_RelativeLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_RelativeLocationStep2);
    emit sig_addLog("black","向纵向移动电机发送相对定位指令");
}

void ServoControl::on_bt_follow_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_Follow);
    emit sig_addLog("black","向纵向移动电机发送根据目标位置变化立即绝对定位指令");
}

void ServoControl::on_bt_oringin_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_OringLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_OringLocationStep2);
    emit sig_addLog("black","向纵向移动电机发送原点定位指令");
}

void ServoControl::on_bt_clearfault_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_ClearInterFault);
    emit sig_addLog("black","向纵向移动电机发送清楚内部故障指令");
}

void ServoControl::on_bt_save_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_Save_uint8,KincoServoManager::Command_Save);
    emit sig_addLog("black","向纵向移动电机发送保存指令");
}

void ServoControl::on_bt_reboot_2_clicked()
{
    emit sig_setParams(servoCanNo[1],KincoServoManager::RW_DeviceReboot_uint16,KincoServoManager::Comman_Reboot);
    emit sig_addLog("black","向纵向移动电机发送重启指令");
}

void ServoControl::on_bt_flush_clicked()
{
    emit sig_setProbe(servoCanNo[0],1);
    emit sig_addLog("black","刷新横向移动电机读写参数");
}

void ServoControl::on_bt_flush_2_clicked()
{
    emit sig_setProbe(servoCanNo[1],1);
    emit sig_addLog("black","刷新纵向移动电机读写参数");
}

void ServoControl::on_cb_rwwokemode_3_currentIndexChanged(int index)
{
    int8_t workmode = workModeMap.key(index);
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_WorkMode_int8,workmode);
}

void ServoControl::on_ip_rwcontrolword_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwcontrolword_3->text(),value,16))
    {
        //mylog<<"set rw controlword:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,value);
    }
    ui->ip_rwcontrolword_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送控制字："+ui->ip_rwcontrolword_3->text()));
}

void ServoControl::on_ip_rwtargetpositon_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetpositon_3->text(),value,10))
    {
        //mylog<<"set rw targetposition:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_TargetPosition_int32,value);
    }
    ui->ip_rwtargetpositon_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送目标位置："+ui->ip_rwtargetpositon_3->text()));
}

void ServoControl::on_ip_rwtrapespeed_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapespeed_3->text(),value,10))
    {
        //mylog<<"set rw trapespeed:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_TrapeSpeed_u32,value);
    }
    ui->ip_rwtrapespeed_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送梯形速度："+ui->ip_rwtrapespeed_3->text()));
}

void ServoControl::on_ip_rwtrapeacc_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapeacc_3->text(),value,10))
    {
        //mylog<<"set rw trapespeed:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_TrapeAcc_u32,value);
    }
    ui->ip_rwtrapeacc_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送梯形加速度："+ui->ip_rwtrapeacc_3->text()));
}

void ServoControl::on_ip_rwtrapedcc_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapedcc_3->text(),value,10))
    {
        //mylog<<"set rw trapedcc:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_TrapeDec_u32,value);
    }
    ui->ip_rwtrapedcc_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送梯形减速度："+ui->ip_rwtrapedcc_3->text()));
}

void ServoControl::on_ip_rwtargetspeed_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetspeed_3->text(),value,10))
    {
        //mylog<<"set rw targetspeed:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_TargetSpeed_int32,value);
    }
    ui->ip_rwtargetspeed_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送目标速度："+ui->ip_rwtargetspeed_3->text()));
}

void ServoControl::on_ip_rwtargetniuju_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetniuju_3->text(),value,10))
    {
        //mylog<<"set rw targetniuju:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_TargetTorque_int16,value);
    }
    ui->ip_rwtargetniuju_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送目标扭矩："+ui->ip_rwtargetniuju_3->text()));
}


void ServoControl::on_cb_rwcanrate_3_currentTextChanged(const QString &arg1)
{
    int value;
    if(stringToint(arg1,value,10))
    {
        //mylog<<"set rw canrate:"<<value;
        value = value/10;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_CanRate_u8,value);
    }
    emit sig_addLog("black",QString("向旋转电机发送更改Can波特率："+ui->cb_rwcanrate_3->currentText()));
}

void ServoControl::on_ip_rwcanheart_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwcanheart_3->text(),value,10))
    {
        //mylog<<"set rw canheart:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_CanHeartTime_u16,value);
    }
    ui->ip_rwcanheart_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送Can心跳时间："+ui->ip_rwcanheart_3->text()));
}

void ServoControl::on_ip_rwencoder_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwencoder_3->text(),value,10))
    {
        //mylog<<"set rw encoderreset:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_EncoderReset_u8,value);
    }
    ui->ip_rwencoder_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送编码器通讯复位："+ui->ip_rwencoder_3->text()));
}

void ServoControl::on_bt_poweroff_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_MotorPowerOff);
    emit sig_addLog("black","向旋转电机发送断电指令");
}

void ServoControl::on_bt_poweion_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_MotorPowerOn);
    emit sig_addLog("black","向旋转电机发送上电指令");
}

void ServoControl::on_bt_quickstop_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_ShutDown);
    emit sig_addLog("black","向旋转电机发送快速停止指令");
}

void ServoControl::on_bt_absolute_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_AbsoluteLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_AbsoluteLocationStep2);
    emit sig_addLog("black","向旋转电机发送绝对定位指令");
}

void ServoControl::on_bt_relative_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_RelativeLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_RelativeLocationStep2);
    emit sig_addLog("black","向旋转电机发送相对定位指令");
}

void ServoControl::on_bt_follow_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_Follow);
    emit sig_addLog("black","向旋转电机发送根据目标位置变化立即绝对定位指令");
}

void ServoControl::on_bt_oringin_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_OringLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_OringLocationStep2);
    emit sig_addLog("black","向旋转电机发送原点定位指令");
}

void ServoControl::on_bt_clearfault_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_ClearInterFault);
    emit sig_addLog("black","向旋转电机发送清楚内部故障指令");
}

void ServoControl::on_bt_save_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_Save_uint8,KincoServoManager::Command_Save);
    emit sig_addLog("black","向旋转电机发送保存指令");
}

void ServoControl::on_bt_reboot_3_clicked()
{
    emit sig_setParams(servoCanNo[2],KincoServoManager::RW_DeviceReboot_uint16,KincoServoManager::Comman_Reboot);
    emit sig_addLog("black","向旋转电机发送重启指令");
}

void ServoControl::on_bt_flush_3_clicked()
{
    emit sig_setProbe(servoCanNo[2],1);
    emit sig_addLog("black","刷新旋转电机读写参数");
}

void ServoControl::on_cb_rwwokemode_4_currentIndexChanged(int index)
{
    int8_t workmode = workModeMap_Step.key(index);
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_WorkMode_int8,workmode);
}

void ServoControl::on_ip_rwcontrolword_4_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwcontrolword_4->text(),value,16))
    {
        //mylog<<"set rw controlword:"<<value;
        emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,value);
    }
    ui->ip_rwcontrolword_4->clearFocus();
    emit sig_addLog("black",QString("向伸缩电机发送控制字："+ui->ip_rwcontrolword_4->text()));
}

void ServoControl::on_ip_rwtargetpositon_4_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetpositon_4->text(),value,10))
    {
        //mylog<<"set rw targetposition:"<<value;
        emit sig_setParams(servoCanNo[3],KincoServoManager::RW_TargetPosition_int32,value);
    }
    ui->ip_rwtargetpositon_4->clearFocus();
    emit sig_addLog("black",QString("向伸缩电机发送目标位置："+ui->ip_rwtargetpositon_4->text()));
}

void ServoControl::on_ip_rwtrapespeed_4_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapespeed_4->text(),value,10))
    {
        //mylog<<"set rw trapespeed:"<<value;
        emit sig_setParams(servoCanNo[3],KincoServoManager::RW_TrapeSpeed_u32,value);
    }
    ui->ip_rwtrapespeed_4->clearFocus();
    emit sig_addLog("black",QString("向伸缩电机发送梯形速度："+ui->ip_rwtrapespeed_4->text()));
}

void ServoControl::on_ip_rwtrapeacc_4_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapeacc_4->text(),value,10))
    {
        //mylog<<"set rw trapespeed:"<<value;
        emit sig_setParams(servoCanNo[3],KincoServoManager::RW_TrapeAcc_u32,value);
    }
    ui->ip_rwtrapeacc_4->clearFocus();
    emit sig_addLog("black",QString("向伸缩电机发送梯形加速度："+ui->ip_rwtrapeacc_4->text()));
}

void ServoControl::on_ip_rwtargetspeed_4_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtargetspeed_4->text(),value,10))
    {
        //mylog<<"set rw targetspeed:"<<value;
        emit sig_setParams(servoCanNo[3],KincoServoManager::RW_TargetSpeed_int32,value);
    }
    ui->ip_rwtargetspeed_4->clearFocus();
    emit sig_addLog("black",QString("向伸缩电机发送目标速度："+ui->ip_rwtargetspeed_4->text()));
}

void ServoControl::on_cb_rwcanrate_4_currentTextChanged(const QString &arg1)
{
    int value;
    if(stringToint(arg1,value,10))
    {
        //mylog<<"set rw canrate:"<<value;
        value = value/10;
        emit sig_setParams(servoCanNo[3],KincoServoManager::RW_CanRate_u8,value);
    }
    emit sig_addLog("black",QString("向伸缩电机发送更改Can波特率："+ui->cb_rwcanrate_4->currentText()));
}

void ServoControl::on_ip_rwcanheart_4_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwcanheart_4->text(),value,10))
    {
        //mylog<<"set rw canheart:"<<value;
        emit sig_setParams(servoCanNo[3],KincoServoManager::RW_CanHeartTime_u16,value);
    }
    ui->ip_rwcanheart_4->clearFocus();
    emit sig_addLog("black",QString("向伸缩电机发送Can心跳时间："+ui->ip_rwcanheart_4->text()));
}

void ServoControl::on_ip_rwtrapedcc_4_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rwtrapedcc_4->text(),value,10))
    {
        //mylog<<"set rw trapedcc:"<<value;
        emit sig_setParams(servoCanNo[3],KincoServoManager::RW_TrapeDec_u32,value);
    }
    ui->ip_rwtrapedcc_4->clearFocus();
    emit sig_addLog("black",QString("向伸缩电机发送梯形减速度："+ui->ip_rwtrapedcc_4->text()));
}

void ServoControl::on_bt_poweroff_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_MotorPowerOff);
    emit sig_addLog("black","向伸缩电机发送断电指令");
}

void ServoControl::on_bt_poweion_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_MotorPowerOn);
    emit sig_addLog("black","向伸缩电机发送上电指令");
}

void ServoControl::on_bt_quickstop_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_ShutDown);
    emit sig_addLog("black","向伸缩电机发送快速停止指令");
}

void ServoControl::on_bt_absolute_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_AbsoluteLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_AbsoluteLocationStep2);
    emit sig_addLog("black","向伸缩电机发送绝对定位指令");
}

void ServoControl::on_bt_relative_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_RelativeLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_RelativeLocationStep2);
    emit sig_addLog("black","向伸缩电机发送相对定位指令");
}

void ServoControl::on_bt_follow_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_Follow);
    emit sig_addLog("black","向伸缩电机发送根据目标位置变化立即绝对定位指令");
}

void ServoControl::on_bt_oringin_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_OringLocationStep1);
    delay_msec(500);
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_OringLocationStep2);
    emit sig_addLog("black","向伸缩电机发送原点定位指令");
}

void ServoControl::on_bt_clearfault_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_ControlWord_u16,KincoServoManager::ControlWord_ClearInterFault);
    emit sig_addLog("black","向伸缩电机发送清楚内部故障指令");
}

void ServoControl::on_bt_save_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_Save_uint8,KincoServoManager::Command_Save);
    emit sig_addLog("black","向伸缩电机发送保存指令");
}

void ServoControl::on_bt_reboot_4_clicked()
{
    emit sig_setParams(servoCanNo[3],KincoServoManager::RW_DeviceReboot_uint16,KincoServoManager::Comman_Reboot);
    emit sig_addLog("black","向伸缩电机发送重启指令");
}

void ServoControl::on_bt_flush_4_clicked()
{
    emit sig_setProbe(servoCanNo[3],1);
    emit sig_addLog("black","刷新伸缩电机读写参数");
}

void ServoControl::on_ip_rworinginmode_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rworinginmode->text(),value,10))
    {
        //mylog<<"set rw trapedcc:"<<value;
        emit sig_setParams(servoCanNo[0],KincoServoManager::RW_OriginMode_u8,value);
    }
    ui->ip_rworinginmode->clearFocus();
    emit sig_addLog("black",QString("向横向电机发送原点模式："+ui->ip_rworinginmode->text()));
}

void ServoControl::on_ip_rworinginmode_2_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rworinginmode_2->text(),value,10))
    {
        //mylog<<"set rw trapedcc:"<<value;
        emit sig_setParams(servoCanNo[1],KincoServoManager::RW_OriginMode_u8,value);
    }
    ui->ip_rworinginmode_2->clearFocus();
    emit sig_addLog("black",QString("向纵向电机发送原点模式："+ui->ip_rworinginmode_2->text()));
}

void ServoControl::on_ip_rworinginmode_3_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rworinginmode_3->text(),value,10))
    {
        //mylog<<"set rw trapedcc:"<<value;
        emit sig_setParams(servoCanNo[2],KincoServoManager::RW_OriginMode_u8,value);
    }
    ui->ip_rworinginmode_3->clearFocus();
    emit sig_addLog("black",QString("向旋转电机发送原点模式："+ui->ip_rworinginmode_3->text()));
}

void ServoControl::on_ip_rworinginmode_4_returnPressed()
{
    int value;
    if(stringToint(ui->ip_rworinginmode_4->text(),value,10))
    {
        //mylog<<"set rw trapedcc:"<<value;
        emit sig_setParams(servoCanNo[3],KincoServoManager::RW_OriginMode_u8,value);
    }
    ui->ip_rworinginmode_4->clearFocus();
    emit sig_addLog("black",QString("向伸缩电机发送原点模式："+ui->ip_rworinginmode_4->text()));
}

void ServoControl::on_btn_movexy_clicked()
{
    int axisX,axisY;
    if(stringToint(ui->ip_X->text(),axisX,10) && stringToint(ui->ip_Y->text(),axisY,10))
    {
        //mylog<<"set rw trapeacc:"<<value;
        emit sig_moveCmd("MOVEXY",axisX,axisY,"");
    }

    emit sig_addLog("black",QString("发送坐标移动指令X："+ui->ip_X->text()+" Y:"+ui->ip_Y->text()));
}

void ServoControl::on_btn_movez_clicked()
{
    int axisZ;
    if(stringToint(ui->ip_Z->text(),axisZ,10))
    {
        //mylog<<"set rw trapeacc:"<<value;
        emit sig_moveCmd("MOVEZ",axisZ,0,"");
    }

    emit sig_addLog("black",QString("发送坐标移动指令Z："+ui->ip_Z->text()));
}

void ServoControl::on_btn_rotate_clicked()
{
    int rotate;
    if(stringToint(ui->ip_rotate->text(),rotate,10))
    {
        //mylog<<"set rw trapeacc:"<<value;
        emit sig_moveCmd("MOVEROTATE",rotate,0,"");
    }

    emit sig_addLog("black",QString("发送旋转指令："+ui->ip_rotate->text()+"°"));
}

void ServoControl::on_btn_clmap_clicked()
{
    //mylog<<"set rw trapeacc:"<<value;
    emit sig_moveCmd("MOVECLAMP",1,0,"");

    emit sig_addLog("black",QString("向5号电机发送夹取指令"));
}

void ServoControl::on_btn_loosen_clicked()
{
    //mylog<<"set rw trapeacc:"<<value;
    emit sig_moveCmd("MOVECLAMP",0,0,"");

    emit sig_addLog("black",QString("向5号电机发送松开指令"));
}

void ServoControl::on_btn_rotateorigin_clicked()
{
    emit sig_moveCmd("MOVEROTATE",0,0,"Origin");
    emit sig_addLog("black",QString("发送3号电机旋转至原点指令"));
}

void ServoControl::on_btn_rotateA_clicked()
{
    emit sig_moveCmd("MOVEROTATE",0,0,"FaceA");
    emit sig_addLog("black",QString("发送3号电机旋转至A面指令"));
}

void ServoControl::on_btn_rotateB_clicked()
{
    emit sig_moveCmd("MOVEROTATE",0,0,"FaceB");
    emit sig_addLog("black",QString("发送3号电机旋转至B面指令"));
}

void ServoControl::on_btn_zrotateA_clicked()
{
    emit sig_moveCmd("MOVEZ",0,0,"In");
    emit sig_addLog("black",QString("发送4号电机移动进指令"));
}

void ServoControl::on_btn_zrotateB_clicked()
{
    emit sig_moveCmd("MOVEZ",0,0,"Out");
    emit sig_addLog("black",QString("发送4号电机移动出指令"));
}

void ServoControl::on_ck_storge_stateChanged(int arg1)
{
    if(arg1 == Qt::CheckState::Checked)
        ui->ck_fetch->setCheckState(Qt::CheckState::Unchecked);
}

void ServoControl::on_ck_fetch_stateChanged(int arg1)
{
    if(arg1 == Qt::CheckState::Checked)
        ui->ck_storge->setCheckState(Qt::CheckState::Unchecked);
}

void ServoControl::on_btn_inoutcabcmd_clicked()
{
    if(ui->ip_storgex->text().isEmpty() || ui->ip_storgey->text().isEmpty())
    {
        QMessageBox msgBox;
        msgBox.setText("请填写货位位置！");
        msgBox.exec();
        return;
    }
    if(ui->ip_portx->text().isEmpty() || ui->ip_porty->text().isEmpty())
    {
        QMessageBox msgBox;
        msgBox.setText("请填写出货口位置！");
        msgBox.exec();
        return;
    }
    if(ui->ck_fetch->checkState() == Qt::CheckState::Unchecked && ui->ck_storge->checkState() == Qt::CheckState::Unchecked)
    {
        QMessageBox msgBox;
        msgBox.setText("请选择存档案或者取档案！");
        msgBox.exec();
        return;
    }
    if(ui->ck_facea->checkState() == Qt::CheckState::Unchecked && ui->ck_faceb->checkState() == Qt::CheckState::Unchecked)
    {
        QMessageBox msgBox;
        msgBox.setText("请选择存取A面或者B面！");
        msgBox.exec();
        return;
    }
    InOutCabCommand_Board cmd = packInOutCabCmd();
    lastCmd = cmd;
    emit sig_inOutCabCmd(cmd);
    QString str;
    if(cmd.Type == ARVCMDTYPE::type_incab)
        str = "存档案，";
    else
        str = "取档案，";
    if(cmd.Face == ARVCMDFACE::face_a)
        str = "A面，";
    else
        str = "B面，";
    if(cmd.isDebug == true)
        str = str + "调试";
    else
        str = str + "非调试";
    emit sig_addLog("black",QString("发送出入柜移动指令：出货口坐标(%1,%2)，货位坐标(%3,%4)，%5")
                    .arg(cmd.PortLocation_X)
                    .arg(cmd.PortLocation_Y)
                    .arg(cmd.StorgeLocation_X)
                    .arg(cmd.StorgeLocation_Y)
                    .arg(str));
}

void ServoControl::on_btn_inoutcabnext_clicked()
{
    if(ui->ck_cmdstep->checkState() == Qt::CheckState::Checked)
    {
        InOutCabCommand_Board cmd = packInOutCabCmd();
        if(cmd == lastCmd)
        {
            emit sig_inOutCabCmd(cmd);
            QString str;
            if(cmd.Type == ARVCMDTYPE::type_incab)
                str = "存档案，";
            else
                str = "取档案，";
            if(cmd.Face == ARVCMDFACE::face_a)
                str += "A面，";
            else
                str += "B面，";
            if(cmd.isDebug == true)
                str = str + "调试";
            else
                str = str + "非调试";
            emit sig_addLog("black",QString("发送出入柜移动指令：出货口坐标(%1,%2)，货位坐标(%3,%4)，%5,下一步")
                            .arg(cmd.PortLocation_X)
                            .arg(cmd.PortLocation_Y)
                            .arg(cmd.StorgeLocation_X)
                            .arg(cmd.StorgeLocation_Y)
                            .arg(str));
        }

        else
        {
            QMessageBox msgBox;
            msgBox.setText("当前指令与上一条下发指令不同！");
            msgBox.exec();
        }
    }
    else
    {
        QMessageBox msgBox;
        msgBox.setText("请选择指令为调试状态！");
        msgBox.exec();
    }
}

void ServoControl::on_btn_rise_clicked()
{
    emit sig_moveCmd("MOVERISE",0,0,"");
    emit sig_addLog("black",QString("发送抬升指令"));
}

void ServoControl::on_btn_fall_clicked()
{
    emit sig_moveCmd("MOVEFALL",0,0,"");
    emit sig_addLog("black",QString("发送下降指令"));
}

void ServoControl::on_btn_stop_clicked()
{
    emit sig_moveCmd("MOVESTOP",0,0,"STOP");
    emit sig_addLog("black",QString("发送全部停止指令"));
}

void ServoControl::on_btn_zarb_clicked()
{
    emit sig_moveCmd("MOVEZARB",0,0,"");
    emit sig_addLog("black",QString("发送Z轴A面，旋转B面指令"));
}

void ServoControl::on_btn_zbra_clicked()
{
    emit sig_moveCmd("MOVEZBRA",0,0,"");
    emit sig_addLog("black",QString("发送Z轴B面，旋转A面指令"));
}

void ServoControl::on_btn_nostop_clicked()
{
    emit sig_moveCmd("MOVESTOP",0,0,"NOSTOP");
    emit sig_addLog("black",QString("发送解除停止指令"));
}

void ServoControl::on_btn_image_clicked()
{
    emit sig_imgCmd();
    emit sig_addLog("black",QString("发送拍照指令"));
}
